package com.koron.system.langfield;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.business.langfield.bean.LangFormBean;
import com.koron.common.core.business.langfield.service.LangFormService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/LangForm")
@Api(tags = "系统管理-配置管理-多语言表单")
public class LangFormController {

    @Autowired
    private LangFormService langformservice;

    @PostMapping("addLangForm")
    @ApiOperation(value = "新增多语言表单")
    public Response addLangForm(@RequestBody LangFormBean langformbean) {
        return ADOConnection.runTask(langformservice, "addLangForm", Response.class, langformbean);
    }

    @GetMapping("removeLangForm")
    @ApiOperation(value = "删除多语言表单")
    public Response removeLangForm(@RequestParam("id") String id) {
        return ADOConnection.runTask(langformservice, "removeLangForm", Response.class, id);
    }

    @PostMapping("updateLangForm")
    @ApiOperation(value = "修改")
    public Response updateLangForm(@RequestBody LangFormBean langformbean) {
        return ADOConnection.runTask(langformservice, "updateLangForm", Response.class, langformbean);
    }

    @GetMapping("queryDet")
    @ApiOperation(value = "明细 传 Id 或者 formKey")
    public Response queryDet(PageQuery query,
                             @RequestParam(value = "id", required = false) String id,
                             @RequestParam(value = "formKey", required = false) String formKey,
                             @RequestParam(value = "fieldKey", required = false) String fieldKey,
                             @RequestParam(value = "lang", required = false) String lang) {
        if (StrUtil.isBlank(id) && StrUtil.isBlank(formKey)) {
            Assert.isFalse(true, "标识不能为空");
        }
        return ADOConnection.runTask(langformservice, "queryDet", Response.class, id, formKey,fieldKey, lang, query);
    }

    @GetMapping("fieldTreeBuild")
    @ApiOperation(value = "字段树构建")
    public Response fieldTreeBuild() {
        return ADOConnection.runTask(langformservice, "fieldTreeBuild", Response.class);
    }

    @GetMapping("queryByClassifyId")
    @ApiOperation(value = "分类找表单")
    public Response queryByClassifyId(PageQuery query,
                                      @RequestParam(value = "classifyId", required = false) String classifyId,
                                      @RequestParam(value = "formName", required = false) String formName) {
        return ADOConnection.runTask(langformservice, "queryByClassifyId", Response.class, classifyId, formName, query);
    }

    @PostMapping("jsonExport")
    @ApiOperation(value = "导出json")
    public Response jsonExport(@RequestBody List<String> ids) {
        return ADOConnection.runTask(langformservice, "jsonExport", Response.class, ids);
    }

    @PostMapping("jsonImp")
    @ApiOperation(value = "导入json")
    public Response jsonImp(@RequestParam("classifyId") String classifyId, @RequestBody List<LangFormBean> dtolist) {
        return ADOConnection.runTask(langformservice, "jsonImp", Response.class, classifyId, dtolist);
    }
}
